package nxu.it.controller;

import nxu.it.model.Todo;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.boot.web.MimeType;
import org.noear.solon.core.handle.MethodType;
import org.noear.solon.core.handle.ModelAndView;

import java.util.ArrayList;
import java.util.List;


@Controller
public class TodoController {
    List<Todo> todoList = new ArrayList<>() ;

    {
        todoList.add(new Todo("吃饭",true));
        todoList.add(new Todo("锻炼",true));
        todoList.add(new Todo("mjh837写作业",true));
        todoList.add(new Todo("睡觉",false));
    }

    @Mapping(value = "/todo/list", method = MethodType.GET, produces = MimeType.TEXT_HTML_VALUE)
    public ModelAndView list() {
        ModelAndView mv = new ModelAndView("todo/list.ftl");
//        todoList.addAll(List.of(
//                new Todo("吃饭",true),
//                new Todo("锻炼",true),
//                new Todo("mjh837写作业",true),
//                new Todo("睡觉",false)
//        ));
        mv.put("todoList", todoList);
        return mv;
    }




        @Mapping(value = "/todo/save", method = MethodType.POST, produces = MimeType.TEXT_HTML_VALUE)
        public ModelAndView save(String content) {
            Todo todo = new Todo(content);
          todoList.add(todo);
      ModelAndView mv = new ModelAndView("todo/success.ftl");
      mv.put("todoList", todoList);
      return mv;

            }

            }



